package com.codejiwei.core.graphx

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx.Graph
import org.apache.spark.graphx.util.GraphGenerators
import org.apache.spark.sql.SparkSession

object GraphXExampleShow {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[2]").setAppName("GraphVisualizationExample")
    val sc = new SparkContext(conf)
    val graph = GraphGenerators
      .logNormalGraph(sc, numVertices = 5)
      .mapVertices((id, _) => s"Node $id")

//    val edgesCSV = graph.edges.map(e => s"${e.srcId},${e.dstId},${e.attr}")
//    edgesCSV.saveAsTextFile("/path/to/edgesCSV")
//
//    val verticesCSV = graph.vertices.map(v => s"${v._1},${v._2}")
//    verticesCSV.saveAsTextFile("/path/to/verticesCSV")


    graph.vertices.collect().foreach(println)
    graph.edges.collect().foreach(println)

    // 关闭 SparkContext
    sc.stop()



  }
}
